home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November A / PCWK1103A.iso / ABBYY FineReader 7.0 PRO / data1.cab / gs_dps.ps < prev    next >
Text File  |  2002-02-23  |  8KB  |  203 lines

  1. %    Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_dps.ps,v 1.4.6.1 2002/02/22 19:45:55 ray Exp $
  14. % Initialization file for Display PostScript functions.
  15.  
  16. % ------ Contexts ------ %
  17.  
  18. % To create a context with private local VM, we use the .localfork
  19. % operator to actually create the context, the new VM, and an empty
  20. % userdict, and then we call the .initlocaldicts procedure to make
  21. % local copies of the initial contents of the dictionaries in local VM.
  22. % savedlocaldicts in systemdict is a global read-only dictionary whose
  23. % elements are global read-only copies of these initial contents;
  24. % we just copy its elements into local VM and install them in systemdict.
  25. % userdict and internaldict require special handling.
  26.  
  27. % Switching between contexts with different local VMs requires
  28. % changing the bindings in systemdict that reference local objects.
  29. % For this purpose, each userdict has an entry called localdicts
  30. % which holds the local copies of the elements of savedlocaldicts,
  31. % plus internaldict.  The context switching code in the interpreter
  32. % effectively copies this dictionary into systemdict.
  33. % NOTE: the name localdicts is known to the interpreter.
  34.  
  35. % Switching between contexts also requires resetting the user parameters.
  36. % The interpreter records the value of userparams (a local dictionary
  37. % referenced from systemdict) for each context, and uses it for this.
  38. % See gs_lev2.ps for more details.
  39. % NOTE: the name userparams is known to the interpreter.
  40.  
  41. % Save copies of local dictionaries at the end of system initialization.
  42. % Also save the initial gstate.
  43. /.savelocalstate {
  44.   .currentglobal true .setglobal
  45.   //systemdict /savedlocaldicts mark //systemdict {
  46.     dup gcheck {
  47.       pop pop
  48.     } {
  49.       dup type /dicttype eq {
  50.         % Save a copy of this dictionary in global VM.
  51.     dup maxlength dict .copydict readonly
  52.       } {
  53.     pop pop
  54.       } ifelse
  55.     } ifelse
  56.   } forall .dicttomark readonly put
  57.         % Create localdicts for the current context.
  58.   false .setglobal
  59.   userdict /localdicts mark savedlocaldicts {
  60.     pop dup load
  61.   } forall /internaldict dup load
  62.   .dicttomark readonly put
  63.         % Save a copy of the initial gstate.
  64.   true .setglobal
  65.   //systemdict /savedinitialgstate gstate readonly put
  66.   .setglobal
  67. } .bind def
  68.  
  69. % Initialize local dictionaries and gstate when creating a new context.
  70. % Note that until this completes, we are in the anomalous situation of
  71. % having systemdict point to dictionaries that are in a non-current
  72. % local VM.  Because of this, we turn off garbage collection temporarily.
  73. /.copylocal {        % <name> <dict> .copylocal <name> <dict'>
  74.         % Copy a dictionary to the current (local) VM,
  75.         % and make it read-only if its current definition is.
  76.   dup maxlength dict .copydict
  77.   1 index load wcheck not { readonly } if
  78. } .bind def
  79. % When this is called, the dictionary stack is in its initial state,
  80. % and there is (anomalously) only one gstate on the gstate stack.
  81. /.initlocaldicts {        % - .initlocaldicts -
  82.   -2 vmreclaim
  83.   .currentglobal //systemdict begin
  84.   false .setglobal
  85.         % Since localdicts doesn't exist yet, references from
  86.         % systemdict to local objects won't get restored if
  87.         % a context switch happens in this code.  Therefore,
  88.         % until localdicts is defined, we have to keep all our
  89.         % state on the operand stack.
  90.  
  91.         % Acquire userdict.
  92.         %****** WRONG IF NON-STANDARD INITIAL DSTACK ******
  93.   countdictstack array dictstack
  94.    { dup gcheck not { exit } if pop } forall
  95.         % Create localdicts with a local copy of each dictionary,
  96.         % except for userdict and userparams, which just need
  97.         % to be filled in.
  98.   mark savedlocaldicts {
  99.     1 index /userdict eq {
  100.         % Stack: userdict mark ... /userdict inituserdict
  101.       counttomark 1 add index .copydict
  102.     } {
  103.       1 index /userparams eq {
  104.         % Stack: userdict mark ... /userparams inituserparams
  105.     userparams .copydict
  106.       } {
  107.     .copylocal
  108.       } ifelse
  109.     } ifelse
  110.   } forall /internaldict dup .makeinternaldict .makeoperator
  111.   .dicttomark readonly /localdicts exch put
  112.         % localdicts is now defined in userdict.
  113.         % Copy the definitions into systemdict.
  114.   localdicts { .forcedef } forall
  115.         % Set the user parameters.
  116.   userparams readonly .setuserparams
  117.         % Establish the initial gstate(s).
  118.   /savedinitialgstate .systemvar setgstate gsave
  119.         % Wrap up.
  120.   end .setglobal
  121. } odef
  122.  
  123. % Check whether an object is a procedure.
  124. /.proccheck {            % <obj> .proccheck <bool>
  125.   dup xcheck
  126.   exch type dup /arraytype eq exch /packedarraytype eq or and
  127. } bind def
  128.  
  129. % Create a context with private local VM.
  130. % The .localfork operator does all the work, but we must ensure that
  131. % .initlocaldicts gets called when the new context starts up.
  132. /localfork {            % <mark> <obj1> ... <objN> <proc>
  133.                 %   <stdin|null> <stdout|null>
  134.                 %   localfork <context>
  135.   .currentglobal true .setglobal 3 index
  136.   dup .proccheck not {
  137.     pop .setglobal /localfork cvx /typecheck signalerror
  138.   } if
  139.   {exec .initlocaldicts} aload pop
  140.   3 1 roll 3 packedarray cvx
  141.   4 1 roll 5 -1 roll pop .setglobal .localfork
  142. } odef
  143.  
  144. % Fork a context that shares VM.  The .fork operator creates an empty
  145. % userparams dictionary for the context, but we still need to initialize
  146. % this dictionary when the new context starts up.
  147. /.postfork {        % - .postfork -
  148.     % Initialize the user parameters.
  149.   savedlocaldicts /userparams get userparams .copydict readonly pop
  150. } odef
  151. /fork {            % <mark> <obj1> ... <objN> <proc> fork <context>
  152.   .currentglobal false .setglobal 1 index
  153.   dup .proccheck not {
  154.     pop .setglobal /fork cvx /typecheck signalerror
  155.   } if
  156.   {exec .postfork} aload pop
  157.   3 1 roll 3 packedarray cvx
  158.   3 1 roll exch pop .setglobal .fork
  159. } odef
  160.  
  161. % ------ Halftone phase ------ %
  162.  
  163. /sethalftonephase {        % <x> <y> sethalftonephase -
  164.   -1 2 index 2 index .setscreenphase pop pop
  165. } odef
  166. /currenthalftonephase {        % - currenthalftonephase <x> <y>
  167.   0 .currentscreenphase
  168. } odef
  169.  
  170. % ------ Device-source images ------ */
  171.  
  172. .imagetypes 2 /.image2 load put
  173.  
  174. % ------ Device information ------ %
  175.  
  176. /.deviceinfodict mark
  177.   /Colors null /GrayValues null /RedValues null /GreenValues null
  178.   /BlueValues null /ColorValues null
  179. .dicttomark readonly def
  180. /deviceinfo {            % - deviceinfo <dict>
  181.   currentdevice //.deviceinfodict .getdeviceparams .dicttomark readonly
  182. } odef
  183.  
  184. % The current implementation allocates a 2-element array each time.
  185. % Perhaps we should change this to 2 separate parameters for X and Y?
  186. /.wtdict mark
  187.   /wtranslation null
  188. .dicttomark readonly def
  189. /wtranslation {            % - wtranslation <x> <y>
  190.   currentdevice //.wtdict .getdeviceparams exch pop exch pop aload pop
  191. } odef
  192. currentdict /.wtdict .undef
  193.  
  194. % ------ View clipping ------ %
  195.  
  196. /rectviewclip {            % <x> <y> <width> <height> rectviewclip -
  197.                 % <numarray|numstring> rectviewclip -
  198.   newpath .rectappend viewclip
  199. } odef
  200.